package com.admin.service.impl;

import com.admin.entity.Admin;
import com.admin.entity.Recharge;
import com.admin.mapper.RechargeMapper;
import com.admin.service.IAdminService;
import com.admin.service.IRechargeService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author marisheng
 * @since 2019-11-21
 */
@Service
public class RechargeServiceImpl extends ServiceImpl<RechargeMapper, Recharge> implements IRechargeService {

    @Autowired
    private RechargeMapper rechargeMapper;


    @Autowired
    private IAdminService adminService;
    /**
     * 沃币充值记录
     * @param map
     * @return
     */
    public List<Map> MoneyRechargeRecord (Map map){
        List<Map> list = rechargeMapper.MoneyRechargeRecord(map);
        return list;
    }
    /**
     *
     * @param admin_id1 要加沃币的用户
     * @param admin_money1 变化的沃币数(+)
     * @param admin_id2 要减沃币的用户
     * @return
     */
    public boolean jia_jian(Integer admin_id1 , Integer admin_money1 , Integer admin_id2){

        int n1 = rechargeMapper.updatemoneyById1(admin_id1 , admin_money1);

        int n2 = rechargeMapper.updatemoneyById2(admin_id2 , admin_money1);


//        if (n1 == 0 || n2 == 0) {
//            throw new RuntimeException("转账失败！");
//        }
        return true;
    }

    /**
     * 新增admin_recharge表
     * @param admin_money 充值沃币数
     * @param admin_id 充值时管理员id
     * @return
     */
    @Override
    public int inseradmin_recharge(Integer admin_money, Integer admin_id) {
        String time = adminService.NowString();
        return  rechargeMapper.insertseradmin_recharge(admin_money , admin_id , time);
    }

    @Override
    public Admin allMoney(Integer admin_id) {
        return rechargeMapper.selctAllMoney(admin_id);
    }



}
